package hot_patch_client_service

import (
	"gitee.com/zaper/kafka-service/kafka_consumer/kafka_consumer_model"
	"gitee.com/zaper/kafka-service/model"
	"gitee.com/zaper/private-logger"
	"sync"
)

var (
	hotPatchClientConsumerOnce   sync.Once
	hotPatchClientConsumerSingle *HotPatchClientConsumer
)

// HotPatchClientConsumer 实现标准消费
type HotPatchClientConsumer struct {
}

func GetHotPatchClientConsumer() *HotPatchClientConsumer {
	hotPatchClientConsumerOnce.Do(func() {
		hotPatchClientConsumerSingle = &HotPatchClientConsumer{}
	})
	return hotPatchClientConsumerSingle
}

func (hotPatchClientConsumer *HotPatchClientConsumer) ConsumerMessage(ch *kafka_consumer_model.ConsumerChan) {
	var message = &model.MessModel{}
	for mess := range ch.MessChan {
		// 读取kafka
		model.ParseConsumerMess(message, &mess)
		switch string(message.Key) {
		case "register":
			register(message.Value)
		case "patch_status":
			patchStatus(message.Value)
		default:
			logger.Infof("key is not exit")
		}
	}
}

func GetHotPatchClientSubModel() *kafka_consumer_model.ConsumerModel {
	return &kafka_consumer_model.ConsumerModel{
		Topic:   "hot_patch",
		GroupID: "hot_patch_client",
	}
}
